using System;
using System.Data;
using System.Linq;
using System.ComponentModel;
using System.Reflection;
using System.Collections.Generic;
using VSSAHT.Transfer;
using VSS_AHT.DataAccess;

namespace VSSAHT.DataAccess
{
	public partial class UserMapper
	{
		#region ToEntity

		public static User ToEntity(User entity, UserDTO businessobject)
		{
			if (businessobject == null)
			{
				return null;
			}
			entity.ModifiedBy = businessobject.ModifiedBy;
			entity.ModifiedDate = businessobject.ModifiedDate;
			entity.PasswordEncrypt = businessobject.PasswordEncrypt;
			entity.RoleID = businessobject.RoleID;
			entity.UserID = businessobject.UserID;
			entity.Username = businessobject.Username;
			entity.RowVersion = VersionConverter.ToBinary(businessobject.RowVersion);
			return entity;
		}

		#endregion

		#region ToBusinessObject

		public static UserDTO ToBusinessObject(User entity)
		{
			if (entity == null)
			{
				return null;
			}
			return new UserDTO
			{
				ModifiedBy = entity.ModifiedBy,
				ModifiedDate = entity.ModifiedDate,
				PasswordEncrypt = entity.PasswordEncrypt,
				RoleID = entity.RoleID,
				UserID = entity.UserID,
				Username = entity.Username,
				Role = RoleMapper.ToBusinessObject(entity.Role),
				RowVersion = VersionConverter.ToString(entity.RowVersion)
			};
		}

		#endregion

		#region ToBusinessObjectHasChildren

		public static UserDTO ToBusinessObjectHasChildren(User entity, params Type[] types)
		{
			if (entity == null)
			{
				return null;
			}
			UserDTO businessobject = new UserDTO
			{
				ModifiedBy = entity.ModifiedBy,
				ModifiedDate = entity.ModifiedDate,
				PasswordEncrypt = entity.PasswordEncrypt,
				RoleID = entity.RoleID,
				UserID = entity.UserID,
				Username = entity.Username,
				Role = RoleMapper.ToBusinessObject(entity.Role),
				RowVersion = VersionConverter.ToString(entity.RowVersion)
			};
			return businessobject;
		}

		#endregion

	}
}
